package sair.recorder.sys;

import sair.sacoms.MathCast;

public class User {
	private Long hash;

	public User(String name, int pwhash) {
		this.name = name;
		this.pwhash = pwhash;
		this.hash = makeHash();
	}

	private String name;
	private int pwhash;

	public boolean equals(Object u) {
		if (u != null && u instanceof User) {
			Long rme = this.hash;
			Long ru = ((User) u).hash;
			if (rme == null || ru == null)
				return false;
			else if (rme.equals(ru))
				return true;
		}
		return false;
	}

	private Long makeHash() {
		StringBuilder sbuf = new StringBuilder();
		if (name == null || name.length() > 4)
			return null;
		char[] nameChars = name.toCharArray();
		for (char nameChar : nameChars)
			sbuf.append((int) nameChar);
		long numberName = MathCast.StrMathCustoLong(sbuf.toString()) + pwhash;
		while (true) {
			if (numberName > Integer.MAX_VALUE)
				numberName -= Integer.MAX_VALUE;
			else
				break;
		}
		return numberName;
	}

	public String toString() {
		return String.valueOf(hash);
	}
}
